
//*************************************************************************************//

/*
function calendario(nom_campo,formato) {
var matParam = new Array(3);
matParam[0] = window;
matParam[1] = nom_campo;
window.showModalDialog('images/pl_calendario.htm',matParam,'dialogHeight:210px; dialogWidth:280px;center:no; help:no; resizable:no; status:no');
}
*/

function esEmail(string) //string = cadena que representa al correo electronico
{//valida si la entrada es un correo electronico si es cierto devuelve true
	  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		  return true;
		else
		  return false;
}


//**********************************************

function maximize(){
if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
  }
}

//**********************************************
function ir_pagina(objeto, tipo_pagina, pagina, ruta) {
	with(objeto) {
         objeto.target="";
		if (tipo_pagina=="S") 	hid_pagina.value = pagina
		if (tipo_pagina=="A") 	hid_pagina.value = pagina
		if (tipo_pagina=="N") 	hid_pagina.value = cmb_paginacion.value;
		action = ruta;
		submit();		
	}
}

//***********************************************
function check_all(form)  {
	for(i=0 ; i<form.elements.length; i++)	{ 
		if(form.elements[i].type == "checkbox")	
             form.elements[i].checked = (form.elements[i].checked) ? false : true;
	}
}


function paginar(url){

	f = document.forms[0];
	cad = url;
	var paramArray = dameParametrosDisplayTag(cad);
	ind1 = url.indexOf('?');
	urlFin = url.substr(0,ind1);
	divisor = '';
	for (i=0; i<paramArray.length; i++){
		divisor = i==0?'?':'&';
		urlFin = urlFin + divisor + paramArray[i];
	}
	f.action=urlFin;
	f.submit();
}

function dameParametrosDisplayTag(url){
	var parArray = new Array();
	var cadIni='';
	temp = url; 
	ind = temp.indexOf('method');
	temp = temp.substring(ind);
	ind = temp.indexOf('&');
	if (ind!=-1){
		cadIni = temp.substr(0,ind);
	}else{
		cadIni = temp.substring(ind);
	}
	
	parArray.push(cadIni);
	var continuar = true;
	while (continuar){
		indice = url.indexOf('d-');
		if (indice != -1){
			// he encontrado un parametro de display
			url = url.substring(indice);
			indice2 = url.indexOf('&');
			parArray.push(url.substr(0,indice2));
			url = url.substring(indice2);
		}else{
			continuar = false;
		}
		
	}
	return parArray;
}


//**********************************************

function maximize(){
if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
  }
}

//**********************************************
function ir_pagina(objeto, tipo_pagina, pagina, ruta) {
	with(objeto) {
         objeto.target="";
		if (tipo_pagina=="S") 	hid_pagina.value = pagina
		if (tipo_pagina=="A") 	hid_pagina.value = pagina
		if (tipo_pagina=="N") 	hid_pagina.value = cmb_paginacion.value;
		action = ruta;
		submit();		
	}
}

//***********************************************
function check_all(form)  {
	for(i=0 ; i<form.elements.length; i++)	{ 
		if(form.elements[i].type == "checkbox")	
             form.elements[i].checked = (form.elements[i].checked) ? false : true;
	}
}
//***********Para validar numeros*************
 function valida_numero(xinput,tipval)
  {
    var xkey=event.keyCode;
	if(tipval=="int")
		if ((xkey < 48) || (xkey > 57)) event.returnValue = false;
	if(tipval=="dec")
		{ if ((xkey < 46) || (xkey > 57)) event.returnValue = false;
                  }  

    
                 
	if(tipval=="str")
		if (((xkey != 32) && (xkey < 65)) || ((xkey > 90) && (xkey < 97))) event.returnValue = false;
	if(tipval=="tlf")
		if (((xkey != 32) && (xkey < 45)) || (xkey > 57)) event.returnValue = false;
		
	if (tipval=="afn")	
	 { if (  ((xkey != 32) && (xkey < 45))  || (xkey > 57)   ||
	           ((xkey < 48) || (xkey > 57))   )   event.returnValue = false;
 	  }
		
  }

//***********Para validar letras*************
function validar(e) { // 1
tecla = (document.all) ? e.keyCode : e.which; // 2
if (tecla==8) return true; // 3
patron =/[A-Za-z\s]/; // 4
te = String.fromCharCode(tecla); // 5
return patron.test(te); // 6
} 




//******************************************************
function checkboxAll(checkList){
  if (checkList!=null) {
	if(!isNaN(checkList.length)){
		for(i=0;i<checkList.length;i++)	{
			if((checkList[i].type=='checkbox')){  
			 checkList[i].checked = true;
			}
		}
	}
	else {
	 checkList.checked = true;
	}
   }
}


//******************************************************
function estaSeleccionado(checkList){
  if (checkList==null) {
     return false;
   }
	if(!isNaN(checkList.length)){
		for(i=0;i<checkList.length;i++)
		{
			if((checkList[i].type=='checkbox') && checkList[i].checked)
			return true;
		}
		return false;
	}
	else return ( (checkList.type=='checkbox') && checkList.checked);
}




//******* scripts para display tag ********************
function onClickCheckBox(field,id){
	var checkedAll = 0;
	var noCheckedAll = 0;
	var objts	= 0;
	var existsTableWithChecks = false;

	for(var i=0;i<document.forms[0].length;i++){
		if(document.forms[0].elements[i].type=="checkbox"){
			if(document.forms[0].elements[i].name != "_checkBox" + id && document.forms[0].elements[i].name == field ) {
				objts ++;
				if( document.forms[0].elements[i].checked )
					checkedAll ++;
				else
					noCheckedAll ++;
			}
			if(document.forms[0].elements[i].name == "_checkBox" + id)
				existsTableWithChecks = true;
		}		
		
			
	}
	
	if(existsTableWithChecks){
		if (checkedAll == objts && objts>0)
			document.all("_checkBox"+id).checked= true;
		else if (noCheckedAll <= objts || objts==0)
			document.all("_checkBox"+id).checked= false;
	}
}


function exportar(){
	document.forms[0].method.value="exportar";
	document.forms[0].submit();
}

